package com.fei.result;

import com.fei.exception.BaseException;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

/**
 * @ Package com.fei.result
 * @ Author  费小钢
 * @ Date 2025/7/20 12:38
 * @ Description:
 * @ Version v1.0
 * @ Copyright @2025-2027 云图一然
 **/
@Data
public class R<T>{
    @Schema(description = "状态码")
    private Integer code;
    @Schema(description = "返回信息")
    private String message;
    @Schema(description = "返回数据")
    private T data;
    public static <T> R<T> success(){
        R<T> r = new R<>();
        r.setCode(200);
        r.setMessage("成功");
        r.setData(null);
        return r;
    }
    public static <T> R<T> success(T data){
        R<T> r = new R<>();
        r.setCode(200);
        r.setMessage("成功");
        r.setData(data);
        return r;
    }
    public static <T> R<T> error(){
        R<T> r = new R<>();
        r.setCode(500);
        r.setMessage("失败");
        r.setData(null);
        return r;
    }
    public static <T> R<T> error(String message){
        R<T> r = new R<>();
        r.setCode(500);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
    public static <T> R<T> error(Integer code,String message){
        R<T> r = new R<>();
        r.setCode(code);
        r.setMessage(message);
        r.setData(null);
        return r;
    }
    public static <T> R<T> error(BaseException  e){
        R<T> r = new R<>();
        r.setCode(e.getCode());
        r.setMessage(e.getMessage());
        r.setData(null);
        return r;
    }
}
